
//4399
if (window['h5api']) {
    let sly = window['sly'] = window['sly'] ? window['sly'] : {}
    class F399RewardAd {
        constructor(_ad) {
            this._ad = ad
            this.loadListener = new sly.SdkEvent()
            this.errorListener = new sly.SdkEvent()
            this.closeListener = new sly.SdkEvent()
            if (this._ad) {
                this._ad.canPlayAd((data) => {
                    this.remain = data.remain
                    this.canPlayAd = data.canPlayAd
                    console.log("loadConfig 是否可播放广告", this.canPlayAd, "剩余次数", this.remain)
                })
            }
        }
        show() {
            this._ad.playAd((obj) => {
                console.log('代码:' + obj.code + ',消息:' + obj.message)
                if (obj.code === 10000) {
                    console.log('开始播放')
                } else if (obj.code === 10001) {
                    console.log('播放结束')
                    this.closeListener.emit({ isEnded: true })
                } else {
                    console.log('广告异常')
                    this.errorListener.emit({ msg: obj.message })
                }
            })
        }
        load() {
            this.loadListener.emit()
        }

        onLoad(func) {
            this.loadListener.on(func)
        }
        offLoad(func) {
            this.loadListener.off(func)
        }
        onError(func) {
            this.errorListener.on(func)
        }
        offError(func) {
            this.errorListener.off(func)
        }
        onClose(func) {
            this.closeListener.on(func)
        }
        offClose(func) {
            this.closeListener.off(func)
        }
    }
    class Parser {
        constructor() {
            this._sdk = window['h5api']
        }

        parse() {
            this._sdk.createRewardedVideoAd = function (obj) {
                return new F399RewardAd(this._sdk)
            }

            // window['wx'] = this._sdk
        }
    }
    new Parser().parse();
}